#include<stdio.h>
#include<string.h>

int countlife(char* s,int m,int n,int w,int l){
	int c = 0;
	if(m-1 >= 0 && n - 1 >= 0 && s[l*(m - 1) + n - 1] == 1){
		++c;
	}
	if(m+1 < w && n + 1 < l && s[l*(m + 1) + n + 1] == 1){
		++c;
	}
	if(m+1 < w && n - 1 >= 0 && s[l*(m + 1) + n - 1] == 1){
		++c;
	}
	if(m-1 >= 0 && n + 1 < l && s[l*(m - 1) + n + 1] == 1){
		++c;
	}
	if(m+1 < w  && s[l*(m + 1) + n] == 1){
		++c;
	}
	if(m-1 >= 0 && s[l*(m - 1) + n] == 1){
		++c;
	}
	if(n + 1 < l && s[l*(m) + n + 1] == 1){
		++c;
	}
	if(n - 1 >= 0 && s[l*(m) + n - 1] == 1){
		++c;
	}
	return c;
}

int main(){
	int m = 0,n = 0,t = 0,x = 0,i = 0,p = 0,q = 0,y = 0;
	char* s1 = NULL;
	char* s2 = NULL;
	char* s = NULL;
	char* tmp = NULL;
	FILE *fin  = fopen ("life.in", "r");
	FILE *fout = fopen ("life.out", "w");
	fscanf(fin,"%d %d %d",&m,&n,&t);
	x = n;
	s = (char*)malloc(sizeof(char) * (m + 1));
	s1 = (char*)malloc(sizeof(char) * (m * n));
	s2 = (char*)malloc(sizeof(char) * (m * n));
	memset(s1,0,sizeof(char) * (m * n));
	while(x){
		fscanf(fin,"%s",s);
		for(i = 0;i < m;++i){
		  if(s[i] == '0'){
			s1[m * (n - x) + i] = 0;
			s2[m * (n - x) + i] = 0;
		  }else{
			s1[m * (n - x) + i] = 1;
			s2[m * (n - x) + i] = 1;
		  }
		}
		--x;
	}
	for(i = 1;i < t;++i){
		for(p = 0;p < n;++p){
		  for(q = 0;q < m;++q){
			y = countlife(s1,p,q,n,m);
			if((s1[p * m + q] == 1 && (y == 2 || y == 3)) || (s1[p * m + q] == 0 && y == 3)){
				s2[p * m + q] = 1;
			}else{
				s2[p * m + q] = 0;
			}
		  }
		}
		for(p = 0;p < n;++p){
		  for(q = 0;q < m;++q){
			s1[p * m + q] = s2[p * m + q];
		  }
		}
	}
	for(p = 0;p < n;++p){
		for(q = 0;q < m;++q){
			fprintf(fout,"%d",s2[p * m + q]);
		}
		fprintf(fout,"\n");
	}
	free(s1);
	free(s2);
	fclose(fin);
	fclose(fout);
	return 0;
}
